const mysql = require('mysql2/promise');

const dbConfig = {
  host: process.env.DB_HOST || "43.143.253.188",
  port: parseInt(process.env.DB_PORT || "3306", 10),
  user: process.env.DB_USER || "nextjs",
  password: process.env.DB_PASS || "yEAiRE2jcxTyRBy5",
  database: process.env.DB_NAME || "nextjs",
  charset: 'utf8mb4',
  timezone: '+08:00',
};

async function checkTableStructure() {
  let connection;
  
  try {
    console.log('🔍 检查表结构...');
    connection = await mysql.createConnection(dbConfig);
    console.log('✅ 连接成功');
    
    // 检查赤壁期数表结构
    console.log('\n📋 赤壁期数表结构:');
    const [columns] = await connection.execute('DESCRIBE casino_chibi_rounds');
    columns.forEach(col => {
      console.log(`  ${col.Field}: ${col.Type} ${col.Null === 'NO' ? 'NOT NULL' : 'NULL'} ${col.Key ? `(${col.Key})` : ''}`);
    });
    
    // 尝试不同的查询方式
    console.log('\n📋 尝试查询赤壁期数:');
    try {
      const result = await connection.execute('SELECT COUNT(*) as count FROM casino_chibi_rounds');
      console.log(`记录数: ${result[0][0].count}`);
    } catch (error) {
      console.log(`❌ 查询记录数失败: ${error.message}`);
    }
    
    try {
      const result = await connection.execute('SELECT id, status, winning_side FROM casino_chibi_rounds LIMIT 1');
      console.log(`第一条记录:`, result[0][0]);
    } catch (error) {
      console.log(`❌ 查询记录失败: ${error.message}`);
    }
    
  } catch (error) {
    console.error('❌ 错误:', error.message);
  } finally {
    if (connection) {
      await connection.end();
    }
  }
}

checkTableStructure();
